<!DOCTYPE html>
{% load staticfiles %}
<html>
<head lang="en">
    <meta charset="UTF-8">
     <!-- 引入jQuery -->
    <script src="http://apps.bdimg.com/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
    <script src="http://code.jquery.com/jquery-latest.js"></script>
     <!-- 引入 Bootstrap -->
     <link href="{% static 'bootstrap/css/bootstrap.min.css' %}" rel="stylesheet" type="text/css">
     <link href="{% static 'bootstrap/css/bootstrap.css' %}" rel="stylesheet" type="text/css">
     <script type="text/javascript" src="{% static 'bootstrap/js/bootstrap.min.js' %}"></script>
     <script type="text/javascript" src="{% static 'bootstrap/js/bootstrap.js' %}"></script>          
     <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
        <![endif]--> 
    <title>数据展示平台</title>         
</head>
<body>
<!-- bootstrap 特性容器 -->
 <div class="container">
     <h1>登录 </h1> 
 </div>
<form class="form-horizontal" role="form" id="logintest" method="post">
  <div class="form-group">
    <label for="firstname" class="col-sm-2 control-label">用户名</label>
    <div class="col-sm-3">
      <input type="text" class="form-control" id="username" placeholder="请输入用户名">
    </div>
  </div>
  <div class="form-group">
    <label for="lastname" class="col-sm-2 control-label">密码</label>
    <div class="col-sm-3">
      <input type="password" class="form-control" id="password" placeholder="请输入密码">
    </div>
  </div>
  <div class="form-group">
    <div class="col-sm-offset-2 col-sm-10">
      <div class="checkbox">
        <label>
          <input type="checkbox">请记住我
        </label>
      </div>
    </div>
  </div>
  <div class="form-group">
    <div class="col-sm-offset-2 col-sm-10">
      <button type="submit" class="btn btn-default">登录</button>
    </div>
  </div>
</form>
<label id="isok"></label>
<script language="javascript" type="text/javascript">
var isshuxin=false
$('#logintest').submit(function(){
    var username=$('#username').val();
    var password=$('#password').val();
          $.ajax({
                type:"POST",
                url:'/my_test/checklogin',
                data:{
                    'username':username,
                    'password':password
                    },
                async: false,
                error: function(request) {
                    $("#isok")[0].innerText=request.status;
                    isshuxin=true;
                },
                success: function(result) {
                  if (result["isLogin"]){
                      document.cookie="username="+username;
                      location.href="/index/?username="+username
                  }
                  else{
                        $("#isok")[0].innerText=result["msg"];
                        $('#username')[0].value="";
                        $('#password')[0].value="";
                  }
                }
            });
            return isshuxin;
});
</script>
</body>
</html>